package cc.idoone.spring_boot_hello.amqp.topic;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @author hemj
 * @since 2017/10/15
 */
@Component
public class TopicRunner implements CommandLineRunner {

	private final RabbitTemplate rabbitTemplate;

	@Autowired
	public TopicRunner(RabbitTemplate rabbitTemplate) {
		this.rabbitTemplate = rabbitTemplate;
	}

	@Override
	public void run(String... args) throws Exception {
		System.out.println("Sending message...");
		rabbitTemplate.convertAndSend(TopicConfig.EXCHANGE, TopicConfig.DIRECT_KEY, "DirectAndTopic " + System.currentTimeMillis());
		rabbitTemplate.convertAndSend(TopicConfig.EXCHANGE, "spring-boot.topic1", "Topic1 " + System.currentTimeMillis());
		rabbitTemplate.convertAndSend(TopicConfig.EXCHANGE, "spring-boot.topic2", "Topic2 " + System.currentTimeMillis());
	}

}
